package edu.zut.hb.ambition.recovery.spring.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import common.annotation.Log;
import common.core.controller.BaseController;
import common.core.domain.AjaxResult;
import common.enums.BusinessType;
import com.ruoyi.system.domain.Recovery;
import com.ruoyi.system.service.IRecoveryService;
import common.utils.poi.ExcelUtil;
import common.core.page.TableDataInfo;


@RestController
@RequestMapping("/system/recovery")
public class RecoveryController extends BaseController
{
    @Autowired
    private IRecoveryService recoveryService;


    @PreAuthorize("@ss.hasPermi('system:recovery:list')")
    @GetMapping("/list")
    public TableDataInfo list(Recovery recovery)
    {
        startPage();
        List<Recovery> list = recoveryService.selectRecoveryList(recovery);
        return getDataTable(list);
    }


    @PreAuthorize("@ss.hasPermi('system:recovery:export')")
    @Log(title = "医疗废料回收", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Recovery recovery)
    {
        List<Recovery> list = recoveryService.selectRecoveryList(recovery);
        ExcelUtil<Recovery> util = new ExcelUtil<Recovery>(Recovery.class);
        util.exportExcel(response, list, "医疗废料回收数据");
    }


    @PreAuthorize("@ss.hasPermi('system:recovery:query')")
    @GetMapping(value = "/{huishouid}")
    public AjaxResult getInfo(@PathVariable("huishouid") Long huishouid)
    {
        return AjaxResult.success(recoveryService.selectRecoveryByHuishouid(huishouid));
    }


    @PreAuthorize("@ss.hasPermi('system:recovery:add')")
    @Log(title = "医疗废料回收", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Recovery recovery)
    {
        return toAjax(recoveryService.insertRecovery(recovery));
    }


    @PreAuthorize("@ss.hasPermi('system:recovery:edit')")
    @Log(title = "医疗废料回收", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Recovery recovery)
    {
        return toAjax(recoveryService.updateRecovery(recovery));
    }


    @PreAuthorize("@ss.hasPermi('system:recovery:remove')")
    @Log(title = "医疗废料回收", businessType = BusinessType.DELETE)
	@DeleteMapping("/{huishouids}")
    public AjaxResult remove(@PathVariable Long[] huishouids)
    {
        return toAjax(recoveryService.deleteRecoveryByHuishouids(huishouids));
    }
}
